function searchFieldChange(e) {
    var label = "";
    if (e && e.selectedIndex){
        label = e.options[e.selectedIndex].text;
    } else {
        var f = document.getElementById("fieldSearch");
        if (!f) return;
        label = f.options[f.selectedIndex].text;
    }
    if (label == "产品") {
        document.getElementById("keyword_span").style.display = "none";
        document.getElementById("product_span").style.display = "block";
    } else {
        document.getElementById("keyword_span").style.display = "block";
        document.getElementById("product_span").style.display = "none";
    }
}

function copyPhoneToFax() {
    document.getElementById("countryCodeFax").value = document.getElementById("countryCode").value;
    document.getElementById("areaCodeFax").value = document.getElementById("areaCode").value;
    document.getElementById("fax").value = document.getElementById("phone").value;
    document.getElementById("extensionFax").value = document.getElementById("extension").value;
}

// control table component's cell size
function setTdWidth(){
    document.getElementById("trElement").childNodes[0].childNodes[1].cells[0].style.cssText = "width:200px;";
    document.getElementById("trElement").childNodes[1].childNodes[1].cells[0].style.cssText = "width:80px;";
    document.getElementById("trElement").childNodes[2].childNodes[1].cells[0].style.cssText = "width:60px;";
    document.getElementById("trElement").childNodes[3].childNodes[1].cells[0].style.cssText = "width:60px;";
    document.getElementById("trElement").childNodes[4].childNodes[1].cells[0].style.cssText = "width:90px;";
    document.getElementById("trElement").childNodes[5].childNodes[1].cells[0].style.cssText = "width:90px;";
}

function setCellWidth(){
    document.getElementById("trElement").childNodes[0].childNodes[1].cells[0].style.cssText = "width:60px;";
    document.getElementById("trElement").childNodes[1].childNodes[1].cells[0].style.cssText = "width:80px;";
    document.getElementById("trElement").childNodes[2].childNodes[1].cells[0].style.cssText = "width:150px;";
    document.getElementById("trElement").childNodes[3].childNodes[1].cells[0].style.cssText = "width:300px;";
    document.getElementById("trElement").childNodes[4].childNodes[1].cells[0].style.cssText = "width:70px;";
}

/**
 * 当页面呈现的时候设置table组件的单元格宽度。
 *
 * @param width value separated by comma
 * @param tab id 
 */
function setTableCellWidth(tabId,widthArgs){
    var arrayValue = widthArgs.split(",");
    var cells = arrayValue.length;
    for(var i=0;i<cells;i++){
        document.getElementById(tabId).childNodes[i].childNodes[1].cells[0].style.cssText = "width:" + arrayValue[i] + "px;";
    }
}


// control Fieldset element show or not show
function showContactDetailInfo(fieldsetElement, tableElement) {
    var cssArgument = document.getElementById(tableElement).style.display;
    if (cssArgument == 'none') {
        document.getElementById(tableElement).style.display = 'block';
    }
    else {
        document.getElementById(tableElement).style.display = 'none';
    }
}


function checkCountry(n, countryName) {
    if (n == 0 && document.getElementById(countryName).value == "中国") {
        document.getElementById(countryName).value = "";
        document.getElementById(countryName).style.cssText = "color:#000";
    }
    if (n == 1 && document.getElementById(countryName).value == "") {
        document.getElementById(countryName).value = "中国";
        document.getElementById(countryName).style.cssText = "color:#aaa";
    }
}

/**
 * 控制集团名称显示
 */
function showGroup() {
    if (!document.getElementById("modify")) return;
    
    if (document.getElementById("isGroup").value == 1) {
        document.getElementById("groupNameDiv").style.cssText = "display:block;"
        document.getElementById("groupInput").style.cssText = "display:block;";
    }
    else {
        document.getElementById("groupNameDiv").style.cssText = "display:none;"
        document.getElementById("groupInput").style.cssText = "display:none;";
    }
}

function showGroupLabShow() {
    var lableText = document.getElementById("ifGroup").innerHTML;
    var directlableText = document.getElementById("ifProxy").innerHTML;
    if (lableText == "是") {
        document.getElementById("groupNameShow").style.cssText = "display:block;"
        document.getElementById("groupNameLab").style.cssText = "display:block;";
    }
    else {
        document.getElementById("groupNameShow").style.cssText = "display:none;"
        document.getElementById("groupNameLab").style.cssText = "display:none;";
    }
    if (directlableText == "是") {
        document.getElementById("directShow").style.cssText = "display:block;"
        document.getElementById("directLab").style.cssText = "display:block;";
    }
    else {
        document.getElementById("directShow").style.cssText = "display:none;"
        document.getElementById("directLab").style.cssText = "display:none;";
    }
}